﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;

namespace HostConfig
{
    public sealed class TaskElement : ConfigurationElement
    {
        public TaskElement()
        {
        }

        public TaskElement(string elementName)
        {
            Name = elementName;
        }

        /// <summary>
        /// 任务名称
        /// </summary>
        [ConfigurationProperty("name", DefaultValue = "fake", IsRequired = true, IsKey = true)]
        [StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\", MaxLength = 50, MinLength = 1)]
        public string Name
        {
            get
            {
                return (string)this["name"];
            }
            set
            {
                this["name"] = value;
            }
        }

        /// <summary>
        /// 任务的Type
        /// </summary>
        [ConfigurationProperty("type")]
        public string Type
        {
            get
            {
                return (string)this["type"];
            }
            set
            {
                this["type"] = value;
            }
        }

        /// <summary>
        /// 任务的名字空间
        /// </summary>
        [ConfigurationProperty("ns")]
        public string Namespace
        {
            get
            {
                return (string)this["ns"];
            }
            set
            {
                this["ns"] = value;
            }
        }

        /// <summary>
        /// 任务的名字空间
        /// </summary>
        [ConfigurationProperty("fullfilename")]
        public string FullFileName
        {
            get
            {
                return (string)this["fullfilename"];
            }
            set
            {
                this["fullfilename"] = value;
            }
        }

        /// <summary>
        /// 任务执行类型
        /// </summary>
        [ConfigurationProperty("runtype", IsRequired = true)]
        public RunType RunType
        {
            get
            {
                return (RunType)this["runtype"];
            }
            set
            {
                this["runtype"] = value;
            }
        }

        /*
        /// <summary>
        /// 执行时间类新
        /// </summary>
        [ConfigurationProperty("runtimetype")]
        public RunTimeType RunTimeType
        {
            get
            {
                return (RunTimeType)this["runtimetype"];
            }
            set
            {
                this["runtimetype"] = value;
            }
        }
        */

        [ConfigurationProperty("ifweekly", DefaultValue = false)]
        public bool IfWeekly
        {
            get
            {
                return (bool)this["ifweekly"];
            }
            set
            {
                this["ifweekly"] = value;
            }
        }

        /// <summary>
        /// 一周中的日期.
        /// ep.0,1,2,3,4,5,6
        /// 分别表示周日,周一,周二,周三,周四,周五,周六
        /// </summary>
        [ConfigurationProperty("daysinweek")]
        public string DaysInWeek
        {
            get
            {
                return (string)this["daysinweek"];
            }
            set
            {
                this["daysinweek"] = value;
            }
        }

        /// <summary>
        /// 执行时间点,非循环执行任务的多点执行时间使用","分隔
        /// </summary>
        [ConfigurationProperty("runtime", IsRequired = true)]
        public string RunTime
        {
            get
            {
                return (string)this["runtime"];
            }
            set
            {
                this["runtime"] = value;
            }
        }

        /// <summary>
        /// 是否在忙时停止
        /// </summary>
        [ConfigurationProperty("stoponbusy", DefaultValue = false)]
        public bool StopOnBusy
        {
            get
            {
                return (bool)this["stoponbusy"];
            }
            set
            {
                this["stoponbusy"] = value;
            }
        }

        /// <summary>
        /// 忙时
        /// e.p. 8:00|11:00,13:00|15:00
        /// </summary>
        [ConfigurationProperty("busytimeinday")]
        public string BusyTimeInDay
        {
            get
            {
                return (string)this["busytimeinday"];
            }
            set
            {
                this["busytimeinday"] = value;
            }
        }

        /// <summary>
        /// 周期
        /// 单位秒
        /// </summary>
        [ConfigurationProperty("cycle", IsRequired = false)]
        public string Cycle
        {
            get
            {
                return (string)this["cycle"];
            }
            set
            {
                this["cycle"] = value;
            }
        }

        /// <summary>
        /// XML格式的配置文件位置
        /// </summary>
        [ConfigurationProperty("cfgfile")]
        public string CfgFile
        {
            get
            {
                return (string)this["cfgfile"];
            }
            set
            {
                this["cfgfile"] = value;
            }
        }

        /// <summary>
        /// 文本的日志文件存放位置
        /// </summary>
        [ConfigurationProperty("logpath")]
        public string LogPath
        {
            get
            {
                return (string)this["logpath"];
            }
            set
            {
                this["logpath"] = value;
            }
        }
    }
}
